<template>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="180px" class="demo-ruleForm">
    <!--        <el-form-item label="编号" prop="id">-->
    <!--          <el-input v-model="ruleForm.id" readonly></el-input>-->
    <!--        </el-form-item>-->
    <el-form-item label="评估号" prop="evaluateid">
      <el-input v-model="ruleForm.evaluateid"></el-input>
    </el-form-item>
    <el-form-item label="评估名称" prop="evaluatename">
      <el-input v-model="ruleForm.evaluatename"></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">确认修改</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        // id:'',
        evaluateid: '',
        evaluatename: ''
      },
      rules: {
        id: [
          { required: true, message: '请填写编号 注意与已存在的编号不要重复', trigger: 'blur' }
        ],
        evaluateid: [
          { required: true, message: '请填写评估号', trigger: 'blur' }
        ],
        evaluatename: [
          { required: true, message: '请填写评估名称', trigger: 'blur' }
        ],
      }
    };
  },
  methods: {
    submitForm(formName) {
      const _this=this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios.put("http://localhost:8081/evaluateindex/update",this.ruleForm).then(function (res){
            if (res.data.msg==="更新成功"){
              _this.$message({
                message: '修改成功！',
                type: 'success'
              });
              //添加成功后页面跳转
              _this.$router.push('/EvaluateIndexList')
            }
            else{
              _this.$message({
                message: '评估号重复！请重新输入',
                type: 'fail'
              });
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  created() {
      const _this=this
      const a=localStorage.getItem("access-schooluser")
      if(a){
        // this.admin=JSON.parse(window.localStorage.getItem('access-admin'))
        axios.get("http://localhost:8081/evaluateindex/selectone/"+this.$route.query.id).then(function (res){
          _this.ruleForm=res.data
        })
      }
      else{
        this.$alert('未登录','提示',{
          confirmButtonText:'确定'
        }).then((res)=>{
          this.$router.replace({path:'/login'})
        })
      }


  }
}
</script>